/*
 * @lc app=leetcode.cn id=476 lang=csharp
 *
 * [476] 数字的补数
 */

// @lc code=start
public class Solution {
    public int FindComplement(int num) {
        int mask = num;
        mask |= mask >> 1;
        mask |= mask >> 2;
        mask |= mask >> 4;
        mask |= mask >> 8;
        mask |= mask >> 16;
        mask = ~mask;
        num |= mask;
        return ~num;
    }
}
// @lc code=end

